package our.pack;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class RenameMetaDataActivity extends Activity {
	
	private MetaDataDataSource metaDataDataSource;
	private PointsDataSource pointsDataSource;
	private MetaData metadata;
	
	private TextView metaDataName;
	private EditText metaDataNewName;
	private Button saveButton;
	
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.renamemetadata);
		
		metaDataDataSource = new MetaDataDataSource(this);
		metaDataDataSource.open();
		pointsDataSource = new PointsDataSource(this);
		pointsDataSource.open();
		
		Intent i = getIntent();
		Bundle b = i.getExtras();
		
		metadata = (MetaData) b.get("MetaData");
		
		metaDataName = (TextView)findViewById(R.id.textmetadataname);
		metaDataNewName = (EditText)findViewById(R.id.editmetadataname);
		saveButton = (Button)findViewById(R.id.buttonsavemetadataname);
		
		metaDataName.setText(metadata.getName());
		
		KlikLuister kl = new KlikLuister();
		saveButton.setOnClickListener(kl);
	}
	
	private class KlikLuister implements OnClickListener{

		public void onClick(View v) {
			if(v.getId() == R.id.buttonsavemetadataname){
				metaDataDataSource.renameMetaData(metadata, metaDataNewName.getText().toString());
				setResult(999);
				finish();
			}
			
		}
	}

}
